<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>原型链的属性</title>
    <script>
        /**
         * 任何构造函数(类型对象)都具有prototype属性，但是Object除外
         * 原型链用于查找属性，读取对象属性值时，会自动到原型链中查找
         * 设置对象属性时，不会查找原型链，如果当前对象中没有属性值，自动添加，所以一般不在原型上添加属性
         */
        console.log(Object.prototype); //原型对象
        console.log(Object.prototype instanceof Object)
        
        function Fun() {
            
        }
        
        Fun.prototype.a = 10;
        
        var fun = new Fun();
        console.log(fun.a)
        
        var fun2 = new Fun();
        fun2.a = 30;
        console.log(fun.a);
        
        function Person(name, age) {
            this.name = name;
            this.age = age;
        }
        
        Person.prototype.setName = function (name) {
            this.name = name;
        }
        
        Person.prototype.setAge = function (age) {
            this.age = age;
        }
        
        let person = new Person();
        person.setName('lzj');
        person.setAge(20);
        
        console.log(person);
        
        let person2 = new Person();
        console.log(person2.__proto__ === person.__proto__) //true
        
    </script>
</head>
<body>
    
</body>
</html>
